// pages/shopGive/shopGive.js
let md5 = require("../../utils/md5.js")
let axios = require("../../utils/util.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    giveInfo: "",
    giveId: "",
    goodsId:""
  },
  giveIdGet(data) {
    this.setData({
      giveId: data.detail.value
    })
    let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _token =
      "userId=" +
      app.globalData.user_id +
      "&token=" +
      app.globalData.userToken +
      "&time=" +
      timestamp +
      "&perfectNumber=" +
      this.data.giveId +
      "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
    let params = {
      userId: app.globalData.user_id,
      token: app.globalData.userToken,
      perfectNumber: this.data.giveId,
      time: timestamp,
      sign: md5.hexMD5(_token),
    };
    axios.axios({
      url: "/user/getUserbyNumber",
      data: params
    }).then((res) => {
      console.log(res.data.result),
        this.setData({
          giveInfo: res.data.result
        })
    })
  },
  deleteInfo() {
    this.setData({
      giveId: "",
      giveInfo: ""
    })
  },
  okgive() {
    let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _token =
      "userId=" +
      app.globalData.user_id +
      "&token=" +
      app.globalData.userToken +
      "&time=" +
      timestamp +
      "&memberId=" +
      this.data.giveInfo.user_id +
      "&goodId=" +
      this.data.goodsId +
      "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
    let params = {
      userId: app.globalData.user_id,
      token: app.globalData.userToken,
      memberId: this.data.giveInfo.user_id,
      goodId:this.data.goodsId,
      time: timestamp,
      sign: md5.hexMD5(_token),
    };
    axios.axios({
      url: "/goods/buygoods",
      data: params
    }).then((res) => {
      console.log(res.data.result),
       wx.showToast({
         title: res.data.text,
         icon:'none'
       })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goodsId:options.goodsId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})